package com.k7.mobile.platform.web.action;


import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

import com.k7.mobile.platform.bo.IAndroidpowerBO;
import com.k7.mobile.platform.bo.IGramBO;
import com.k7.mobile.platform.bo.IGramimageBO;
import com.k7.mobile.platform.dataobject.AndroidpowerDO;
import com.k7.mobile.platform.dataobject.GramDO;
import com.k7.mobile.platform.dataobject.GramimageDO;
import com.k7.mobile.platform.web.support.Constants;

/**
 * 游戏详情页面
 * @author nandi.ldl
 *
 */
public class GameDetailAction extends BaseAction{	
	private static final long serialVersionUID = -5048373149842002950L;

	private Long gameId;
	private IGramBO gramBO;
	private GramDO gramDO;
	private IGramimageBO gramimageBO;
	private IAndroidpowerBO androidpowerBO;
	private List<GramimageDO> imageList = new ArrayList<GramimageDO>();//游戏图片
	private List<GramimageDO> videoList = new ArrayList<GramimageDO>();//游戏视频
	private List<AndroidpowerDO> androidpowerlist;
	
	public String execute() throws Exception {
		if(gameId == null)return ERROR ;
		GramDO param = new GramDO();
		param.setId(gameId);
		
		gramDO = gramBO.getGram(param);
		if(gramDO == null)return ERROR ;
		GramimageDO gramimageDO = new GramimageDO();
		gramimageDO.setGid(gameId);
		gramimageDO.setNeedPaged(Constants.PAGE_NO_NEED_PAGED);
		
		List<GramimageDO> gramimageList = gramimageBO.findList(gramimageDO);
		for (GramimageDO gramimage : gramimageList) {
			if(gramimage.getTypeid() == Constants.GAME_VIDEO){//类型是视频
				videoList.add(gramimage);
			}else{//类型是图片（包括游戏图片、官方图片）
				imageList.add(gramimage);
			}
		}
		

		try{
			String androidPower = gramDO.getAndroidPower();
			if(!StringUtils.isEmpty(androidPower)){
				AndroidpowerDO androidpowerDO = new AndroidpowerDO();
				List<Integer> powerIds = new ArrayList<Integer>();
				for(String str :androidPower.split(","))
					powerIds.add(Integer.valueOf(str));
				androidpowerDO.setIds(powerIds);
				gramimageDO.setNeedPaged(Constants.PAGE_NO_NEED_PAGED);
				androidpowerlist = androidpowerBO.findList(androidpowerDO);
			}
		}catch(Exception e){
			log.error(e);
		}
		return SUCCESS;
	}
	
	
	public Long getGameId() {
		return gameId;
	}

	public void setGameId(Long gameId) {
		this.gameId = gameId;
	}

	public IGramBO getGramBO() {
		return gramBO;
	}

	public void setGramBO(IGramBO gramBO) {
		this.gramBO = gramBO;
	}

	public GramDO getGramDO() {
		return gramDO;
	}

	public void setGramDO(GramDO gramDO) {
		this.gramDO = gramDO;
	}


	public IGramimageBO getGramimageBO() {
		return gramimageBO;
	}


	public void setGramimageBO(IGramimageBO gramimageBO) {
		this.gramimageBO = gramimageBO;
	}


	public List<GramimageDO> getImageList() {
		return imageList;
	}


	public void setImageList(List<GramimageDO> imageList) {
		this.imageList = imageList;
	}


	public List<GramimageDO> getVideoList() {
		return videoList;
	}


	public void setVideoList(List<GramimageDO> videoList) {
		this.videoList = videoList;
	}


	public IAndroidpowerBO getAndroidpowerBO() {
		return androidpowerBO;
	}


	public void setAndroidpowerBO(IAndroidpowerBO androidpowerBO) {
		this.androidpowerBO = androidpowerBO;
	}


	public List<AndroidpowerDO> getAndroidpowerlist() {
		return androidpowerlist;
	}


	public void setAndroidpowerlist(List<AndroidpowerDO> androidpowerlist) {
		this.androidpowerlist = androidpowerlist;
	}	
	
}
